/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28779
 * Date: 2023-08-22
 * Time: 16:36
 */
public class Demo2 {
    //public static Object locker;
    public static void main(String[] args) throws InterruptedException {

        Object locker = new Object();

        Thread t1 = new Thread(() -> {
            synchronized (locker) {
                System.out.println("t1 wait 开始");
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("t1 wait 结束");
            }
        });
        t1.start();
        Thread.sleep(1000);
        System.out.println(t1.getState());

        Thread t2 = new Thread(() -> {

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

            synchronized (locker) {
                System.out.println("t2 notify 开始");
                locker.notify();
                System.out.println("t2 notify 结束");
            }

        });
        t2.start();
    }
}
